Refactor pushEvent promise handling and document promise support#3763
Closed
Refactor pushEvent promise handling and document promise support#3763
Conversation
Harrison1
approved these changes
Apr 16, 2025
SteffenDE
commented
Apr 16, 2025
| As there can be multiple targets, if no callback is passed, a promise is returned that matches the return value of | ||
| [`Promise.allSettled()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled#return_value). | ||
| * `handleEvent(event, (payload) => ...)` - method to handle an event pushed from the server. Returns a value that can be passed to `removeHandleEvent` to remove the event handler. | ||
| * `removeHandleEvent(ref)` - method to remove an event handler added via `handleEvent` |
Collaborator
Author
There was a problem hiding this comment.
This one was not documented, but I think it should be
SteffenDE
commented
Apr 16, 2025
guides/client/js-interop.md
Outdated
| * `liveSocket` - the reference to the underlying `LiveSocket` instance | ||
| * `pushEvent(event, payload, (reply, ref) => ...)` - method to push an event from the client to the LiveView server | ||
| * `pushEvent(event, payload, (reply, ref) => ...)` - method to push an event from the client to the LiveView server. | ||
| If no callback function is passed, a promise that resolves to the reply is returned. |
Collaborator
Author
There was a problem hiding this comment.
We now document the promise support
SteffenDE
commented
Apr 16, 2025
guides/client/js-interop.md
Outdated
Comment on lines
168
to
169
| As there can be multiple targets, if no callback is passed, a promise is returned that matches the return value of | ||
| [`Promise.allSettled()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled#return_value). |
Collaborator
Author
There was a problem hiding this comment.
This commit changes the Promise value, but we did not document it until now, so we should be fine hopefully
SteffenDE
commented
Apr 16, 2025
Comment on lines
+261
to
+263
| {status: "fulfilled", value: {ref: 0, reply: {transactionID: "1001"}}}, | ||
| // we only stubbed one reply | ||
| {status: "rejected", reason: expect.any(Error)} |
Collaborator
Author
There was a problem hiding this comment.
One difference between pushEvent and pushEventTo is that for pushEvent, we only resolve the reply, but here the fulfilled value is { ref, reply }. We could map over the values and remove the ref if we want.
Collaborator
Author
|
We should only merge this for 1.1. For 1.0 if we want to backport, we should skip the pushEvent changes. |
154ae43 to
7c081f0
Compare
7c081f0 to
25c1f75
Compare
SteffenDE
added a commit
that referenced
this pull request
May 8, 2025
This got a bit bigger than expected, but it addresses multiple things: 1. includes type definitions for all public methods and interfaces. No need for `@types/phoenix_live_view`. The exported types are compatible with the currently documented type hints. Editors like VSCode now show detailed Intellisense. 2. rewrites some files in Typescript 3. updates eslint configuration to handle typescript 4. includes #3763 5. changes all commonjs files to modules
SteffenDE
added a commit
that referenced
this pull request
May 8, 2025
This got a bit bigger than expected, but it addresses multiple things: 1. includes type definitions for all public methods and interfaces. No need for `@types/phoenix_live_view`. The exported types are compatible with the currently documented type hints. Editors like VSCode now show detailed Intellisense. 2. rewrites some files in Typescript 3. updates eslint configuration to handle typescript 4. includes #3763 5. changes all commonjs files to modules
SteffenDE
added a commit
that referenced
this pull request
May 8, 2025
This got a bit bigger than expected, but it addresses multiple things: 1. includes type definitions for all public methods and interfaces. No need for `@types/phoenix_live_view`. The exported types are compatible with the currently documented type hints. Editors like VSCode now show detailed Intellisense. 2. rewrites some files in Typescript 3. updates eslint configuration to handle typescript 4. includes #3763 5. changes all commonjs files to modules
SteffenDE
added a commit
that referenced
this pull request
May 12, 2025
This got a bit bigger than expected, but it addresses multiple things: 1. includes type definitions for all public methods and interfaces. No need for `@types/phoenix_live_view`. The exported types are compatible with the currently documented type hints. Editors like VSCode now show detailed Intellisense. 2. rewrites some files in Typescript 3. updates eslint configuration to handle typescript 4. includes #3763 5. changes all commonjs files to modules
SteffenDE
added a commit
that referenced
this pull request
May 19, 2025
* Add type definitions for public interfaces This got a bit bigger than expected, but it addresses multiple things: 1. includes type definitions for all public methods and interfaces. No need for `@types/phoenix_live_view`. The exported types are compatible with the currently documented type hints. Editors like VSCode now show detailed Intellisense. 2. rewrites some files in Typescript 3. updates eslint configuration to handle typescript 4. includes #3763 5. changes all commonjs files to modules * don't rely on typescript for tests * let's call it ViewHook * use typescript in tests * use prettier for js/ts formatting
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
EDIT: the original content of this PR was moved to #3766.
Refactors the pushEvent promise handling.